/* 折线图开始 */
var myChar = echarts.init(document.getElementById('main'));
//视图自适应
window.onresize = myChar.resize;
function echart(xdata,data,name) {
    // 指定图表的配置项和数据
    var option = {
        tooltip: {},
        legend: {
            data: [name],
            bottom: 10
        },
        xAxis: {
            data:xdata
        },
        yAxis: {
            type: 'value',
            position: 'left'
        },
        series: [
            {
                name: name,
                type: 'line',
                data: data,
                areaStyle: {}
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChar.setOption(option);
}
//刷新
$("#refresh").click(function () {
    location.reload();
});
//上架商品总数
getGoodsSum(1,$('#goodsPutOnSum'));
//商品总数
getGoodsSum('',$('#goodsSum'));
function getGoodsSum(productSate,Id) {
    $.ajax({
        url: '/welcome/getGoodsSum',
        type: 'post',
        dataType: 'json',
        data: {'productSate': productSate},
        success: function (data) {
            Id.text(data.data);
        }
    });
}
// 商品销量总数
getGoodsSalesSum(3,'',$('.goodsSalesSum'));

function getGoodsSalesSum(orderType,productSate,Id) {
    $.ajax({
        url: '/welcome/getGoodsSalesSum',
        type: 'post',
        dataType: 'json',
        data: {'orderType': orderType,'productSate':productSate},
        success: function (data) {
            Id.text(data.data);
        }
    });
}
//商品收藏总数
getGoodsCollectSum(3);
function getGoodsCollectSum(collectionType) {
    $.ajax({
        url: '/welcome/getGoodsCollectSum',
        type: 'post',
        dataType: 'json',
        data: {'collectionType': collectionType},
        success: function (data) {
            $('#goodCollenSum').text(data.data);
        }
    });
}
//已完成订单总数
getOrderSum(6, $('.orderCompletedSum'));

//商品待审核量
getExamineSum('2', 3, $('#goodsExamineCount'));
//课程待审核量
getExamineSum('2', 2, $('#courseExamineCount'));
//退订待审核量
getOrderSum(7, $('#unsubscribeCount'));

function getOrderSum(orderStatus, Id) {
    $.ajax({
        url: '/welcome/getOrderSum',
        type: 'post',
        dataType: 'json',
        data: {'orderStatus': orderStatus},
        success: function (data) {
            Id.text(data.data);
        }
    });
}
//商品、课程、微圈待审核量
function getExamineSum(result, type, Id) {
    $.ajax({
        url: '/welcome/getExamineSum',
        type: 'post',
        dataType: 'json',
        data: {'result': result, 'type': type},
        success: function (data) {
            Id.text(data.data);
        }
    });
}
//订单总数
getOrderSum('', $('#orderSum'));

//本月新增商品
getGoodsMonthAddSum();
function getGoodsMonthAddSum() {
    $.ajax({
        url: '/welcome/getGoodsMonthAddSum',
        type: 'post',
        dataType: 'json',
        success: function (data) {
            $('#goodsAddCount').text(data.data);
        }
    });
}
//本月新增商品同比上月百分比
getGoodsPercentage();
function getGoodsPercentage() {
    $.ajax({
        url:'/welcome/getGoodsLastMonthAddSum',
        type:'post',
        dataType:'json',
        success:function (data) {
            $.ajax({
                url: '/welcome/getGoodsMonthAddSum',
                type:'post',
                dataType:'json',
                success:function (item) {
                    $('#goodsPercentage').text(toPercent((item.data-data.data)/data.data))
                }
            });
        }
    });
}
//本周商品新增量
getWeekCount('product_id','js_product');

function getWeekCount(field,table) {
    $.ajax({
        url:'/welcome/getWeekCount',
        type:'post',
        dataType:'json',
        data:{'field':field,'table':table},
        success:function (data) {
            echart(data.data.list,data.data.data,'商品量')
        }
    });
}

//小数转百分比
function toPercent(point){
    var str=Number(point*100).toFixed(0);
    if (str=='NaN'){
        str = 0;
    }
    str+="%";
    return str;
}
$(".quick").on('click',function () {
    parent.$('#Jump').val($(this).attr('data-value'));
    parent.getQuick();
    return;
});